package review.classics;

import java.util.PriorityQueue;

public class topk {
    public static void main(String[] args) {
        int[] num = {1,55,33,66,36,875,4,6,32};
        int k = 4;

        PriorityQueue<Integer> queue = new PriorityQueue<>(k,(a,b)->b-a);

//        for (int i = 0; i < num.length; i++) {
//            queue.add(num[i]);
//        }

        for (int i = 0; i < num.length; i++) {
            if(queue.isEmpty()||queue.size()<k){
                queue.add(num[i]);
            }else if(num[i]<queue.peek()){
                queue.poll();
                queue.add(num[i]);
            }
        }
        while(!queue.isEmpty()){
            System.out.println(queue.poll());
        }

    }
}
